package cn.kgc.springcloud.controller;

import cn.kgc.springcloud.client.ProductClient;
import cn.kgc.springcloud.entity.Product;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

/**
 * @author mosin
 * date 2022/1/4
 * @version 1.0
 */
@RestController
public class CategoryController {
    Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    private ProductClient productClient;
    @GetMapping("/c1")
    public String test01(){
        return "Category service  invoke ok ";
    }

    @GetMapping("/c2")
    public String test02(){
        // 发送http请求的同时 实现负载均衡
        String s = productClient.test01();
        return "Category service  invoke ok " +s;
    }


    @GetMapping("/c3")
    public String test03(){
        // 发送http请求的同时 实现负载均衡
        String s = productClient.test01();
        return "Category service  invoke ok " +s;
    }

    @GetMapping("/c4")
    public String test04(String name,Integer id){
        logger.info("name: {}, id:{}",name,id);
        // 发送http请求的同时 实现负载均衡
        String s = productClient.test02(name,id);
        return "Category service  invoke ok " +s;
    }


    @PostMapping("/c5")
    public String test05(Product product){
        logger.info(product.toString());
        // 发送http请求的同时 实现负载均衡
        String s = productClient.test03(product);
        return "Category service  invoke ok " +s;
    }


    @PostMapping("/c6")
    public String test06(String[] ids){
        logger.info(Arrays.toString(ids));
        // 发送http请求的同时 实现负载均衡
        String s = productClient.test04(ids);
        return "Category service  invoke ok " +s;
    }

    @GetMapping("/c7/{name}/{id}")
    public String test07(@PathVariable String name, @PathVariable Integer id){
        // logger.info(Arrays.toString(ids));
        // 发送http请求的同时 实现负载均衡
        String s = productClient.test05(name,id);
        return "Category service  invoke ok " +s;
    }

    @GetMapping("/c8")
    public String test08(Integer id){
        // 发送http请求的同时 实现负载均衡
        Product product = productClient.test06(id);
        logger.info(product.getName());
        logger.info(product.getId().toString());
        logger.info(product.getPrice()+"");
        return "Category service  invoke ok " +product.toString();
    }

    @GetMapping("/c9")
    public List<Product> test09(Integer id){
        return productClient.test07(id);
    }

}
